package edu.mse.camel.client.eventbus.test.cases;

import java.util.ArrayList;
import java.util.List;

import edu.mse.camel.client.eventbus.pubsub.EventManager;
import edu.mse.camel.client.eventbus.pubsub.ISubscriber;
import edu.mse.camel.client.events.EventIDs;
import edu.mse.camel.client.events.IEvent;

public class SubscriberForMultipleEvents implements ISubscriber {

	private List<String> eventIDsReceived;
	private List<String> eventsIDsSubscribedFor;
	
	public SubscriberForMultipleEvents() {
		eventIDsReceived = new ArrayList<String>();
		eventsIDsSubscribedFor = new ArrayList<String>();
		eventsIDsSubscribedFor.add(EventIDs.ASSIGN_ROLE_EVENT);
		eventsIDsSubscribedFor.add(EventIDs.CREATESESSION_EVENT);
		//eventsIDsSubscribedFor.add(EventIDs.INVITE_PARTICIPANT_EVENT);
		
		EventManager.getInstance().subscribeTo(eventsIDsSubscribedFor.get(0), this);
		EventManager.getInstance().subscribeTo(eventsIDsSubscribedFor.get(1), this);
		EventManager.getInstance().subscribeTo(eventsIDsSubscribedFor.get(2), this);
			
	}
	
	public List<String> getEventIDsSubscribedFor() {
		return eventsIDsSubscribedFor;
	}
	
	@Override
	public void notifyEvent(IEvent e) {
		if (!eventIDsReceived.contains(e.getEventID())) {
			eventIDsReceived.add(e.getEventID());
		}
	}
	
	public List<String> getEventIDsReceived() {
		return eventIDsReceived;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((eventIDsReceived == null) ? 0 : eventIDsReceived.hashCode());
		result = prime
				* result
				+ ((eventsIDsSubscribedFor == null) ? 0 : eventsIDsSubscribedFor
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SubscriberForMultipleEvents other = (SubscriberForMultipleEvents) obj;
		if (eventIDsReceived == null) {
			if (other.eventIDsReceived != null)
				return false;
		} else if (!eventIDsReceived.equals(other.eventIDsReceived))
			return false;
		if (eventsIDsSubscribedFor == null) {
			if (other.eventsIDsSubscribedFor != null)
				return false;
		} else if (!eventsIDsSubscribedFor.equals(other.eventsIDsSubscribedFor))
			return false;
		return true;
	}

}
